package com.es.util.mail;   
  
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**  
 * @desc 设置邮件基本信息  
 */  
public class MailInfo {   
    // 发送邮件的服务器的IP和端口[大多默认为25，gmail：465]   
    private String mailServerHost;   
    private String mailServerPort = "25";   
    //邮件发送者的地址   
    private String fromAddress;   
    //邮件接收者的地址[支持多用户]　   
    private String []toAddress;   
    // 登陆邮件发送服务器的用户名和密码   
    private String userName;   
    private String password;   
    //是否需要身份验证　   
    private boolean validate = false;   
    //邮件主题⡡    
    private String subject;   
    // 邮件的文本内容　   
    private String content;   
    // 邮件附件的文件名[上传文件路径]　   
    private String[] attachFileNames;   
    /**   
     * 获得邮件会话属性　　   
     * @throws IOException 
     */  
     public  MailInfo() throws IOException{    	 
    	// InputStream in = new BufferedInputStream(new FileInputStream("mail.properties"));
   
    	 InputStream in = MailInfo.class.getClassLoader().getResourceAsStream(
    	    "mail.properties");
     	 Properties p = new Properties();
     	 p.load(in);
     	
     	 setMailServerHost(p.getProperty("server_mail_host"));   
         setMailServerPort(p.getProperty("server_mail_port"));   
     	 if(p.containsKey("is_validate"))
     		 setValidate(new Boolean(p.getProperty("is_validate")));   
     	 else
     		 setValidate(false);
         setUserName(p.getProperty("login_user_name"));   
         setPassword(p.getProperty("login_user_pwd"));   
         //--设置邮件服务器结束   
         setFromAddress(p.getProperty("server_mail_address"));//邮件发送者的地址  
    	 
     }  
    
    public Properties getProperties() {   
        Properties p = new Properties();   
        p.put("mail.smtp.host", this.mailServerHost);   
        p.put("mail.smtp.port", this.mailServerPort);   
        p.put("mail.smtp.auth", validate ? "true" : "false");   
        //p.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");//gmail需要    
        return p;   
    }   
    
    public String getMailServerHost() {   
        return mailServerHost;   
    }   
  
    public void setMailServerHost(String mailServerHost) {   
        this.mailServerHost = mailServerHost;   
    }   
  
    public String getMailServerPort() {   
        return mailServerPort;   
    }   
  
    public void setMailServerPort(String mailServerPort) {   
        this.mailServerPort = mailServerPort;   
    }   
  
    public boolean isValidate() {   
        return validate;   
    }   
  
    public void setValidate(boolean validate) {   
        this.validate = validate;   
    }   
  
    public String[] getAttachFileNames() {   
        return attachFileNames;   
    }   
  
    public void setAttachFileNames(String[] fileNames) {   
        this.attachFileNames = fileNames;   
    }   
  
    public String getFromAddress() {   
        return fromAddress;   
    }   
  
    public void setFromAddress(String fromAddress) {   
        this.fromAddress = fromAddress;   
    }   
  
    public String getPassword() {   
        return password;   
    }   
  
    public void setPassword(String password) {   
        this.password = password;   
    }   
  
    public String []getToAddress() {   
        return toAddress;   
    }   
  
    public void setToAddress(String []toAddress) {   
        this.toAddress = toAddress;   
    }   
  
    public String getUserName() {   
        return userName;   
    }   
  
    public void setUserName(String userName) {   
        this.userName = userName;   
    }   
  
    public String getSubject() {   
        return subject;   
    }   
  
    public void setSubject(String subject) {   
        this.subject = subject;   
    }   
  
    public String getContent() {   
        return content;   
    }   
  
    public void setContent(String textContent) {   
        this.content = textContent;   
    }   
}  
